var app =new Vue({
    el:"#xp-wrapper",
    data:{
        info:[],
        price:[],
    },
    mounted:function (){
        this.oldManUserinfo();
        this.WhetherPayment();
    },
    methods:{
        oldManUserinfo:function (){
            axios({
                method: "get",
                url:"yly-api/user/logon/queryOldMan",
                headers:{"token":localStorage.token}
            }).then(function (res){
                console.log(res.data);
                if (res.data.code==200){
                    app.info=res.data.data;
                }else if (res.data.code==500){
                    location.href="500.html";
                }

            }).catch(function (error){
                console.log(error.response.status);
                if (error.response.status==401){
                    alert("请先登录!");
                    location.href="index.html";
                }else if (error.response.status==403){
                    alert("用户已过期，请重新登录！");
                    localStorage.token=null;
                    location.href="index.html";
                }
            })
        },
        chongzhi(index){
            console.log(this.price[index]);
            let data=new URLSearchParams();
            data.append("price",app.price[index]);
            console.log(app.info[index].id);
            data.append("id",app.info[index].id);
            axios({
                method: "post",
                url:"yly-api/user/zf",
                headers:{"token":localStorage.token},
                data:data
            }).then(function (res){
                console.log(res.data);
                $('body').empty().html(res.data);

            }).catch(function (error){
                console.log(error.response.status);
                if (error.response.status==401){
                    alert("请先登录!");
                    location.href="index.html";
                }else if (error.response.status==403){
                    alert("用户已过期，请重新登录！");
                    localStorage.token=null;
                    location.href="index.html";
                }
            })
        },
        WhetherPayment(){
            let status=getQueryString("status");
            if (status=="true"){
                alert("支付成功！");
            }else if (status=="false"){
                alert("支付失败！");
            }else {

            }
        }
    }
});
function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg); //r是一个数组
    if (r != null) return unescape(r[2]); return null;
}